package com.yanqu.road.dao.impl.activity.gashapon;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.gashapon.config.GashaponReward;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author : Cxp
 * @Time : 2024-10-21
 * @Description : 幸运扭蛋-Config Dao
 */

public class GashaponConfigDaoImpl extends TempDao {
    private static String getRewardConfigSql = "SELECT * FROM t_s_activity_lottery_reward WHERE activityId = ?";

    public Map<Integer, GashaponReward> getRewardConfig(int activityId) {
        Map<Integer, GashaponReward> dataMap = new HashMap<>();

        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getRewardConfigSql);
            int i = 1;
            call.setInt(i, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                GashaponReward reward = new GashaponReward(rs);
                dataMap.put(reward.getId(), reward);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }

        return dataMap;
    }
}
